# Maintainer: David Grayson <davidegrayson@gmail.com>

_realname=libftdi
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=1.2
pkgrel=1
pkgdesc='Library to talk to FTDI chips, with Python 2 bindings (mingw-w64)'
arch=('any')
url="https://www.intra2net.com/en/developer/libftdi/"
license=('LGPL', 'GPL')
makedepends=(
  "${MINGW_PACKAGE_PREFIX}-gcc"
  "${MINGW_PACKAGE_PREFIX}-cmake"
  "${MINGW_PACKAGE_PREFIX}-boost"
  "${MINGW_PACKAGE_PREFIX}-swig"
  "${MINGW_PACKAGE_PREFIX}-python2"
)
depends=(
  "${MINGW_PACKAGE_PREFIX}-libusb"
  "${MINGW_PACKAGE_PREFIX}-confuse"
  "${MINGW_PACKAGE_PREFIX}-gettext"
  "${MINGW_PACKAGE_PREFIX}-libiconv"
)
options=('staticlibs' 'strip')
source=(
  "https://www.intra2net.com/en/developer/libftdi/download/libftdi1-${pkgver}.tar.bz2"
)

sha256sums=('a6ea795c829219015eb372b03008351cee3fb39f684bff3bf8a4620b558488d6')

build() {
  rm -rf "${srcdir}/build-${MINGW_CHOST}"
  mkdir -p "${srcdir}/build-${MINGW_CHOST}"
  cd "${srcdir}/build-${MINGW_CHOST}"
  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
  ${MINGW_PREFIX}/bin/cmake \
    -G"MSYS Makefiles" \
    -DCMAKE_INSTALL_PREFIX="${MINGW_PREFIX}" \
    -DCMAKE_BUILD_TYPE=Release \
    -DEXAMPLES=Off \
    -DPYTHON_BINDINGS=On \
    "../${_realname}1-${pkgver}/"

  make
}

check() {
  cd "${srcdir}/build-${MINGW_CHOST}"
  PATH=$PATH:"${srcdir}/build-${MINGW_CHOST}/src" make check
}

package() {
  cd "${srcdir}/build-${MINGW_CHOST}"
  make DESTDIR="${pkgdir}" install

  cd "${srcdir}/${_realname}1-${pkgver}"
  mkdir -p "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}"
  cp COPYING* "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}"

  sed -i "s;$(cygpath -m /);/;" \
      "${pkgdir}${MINGW_PREFIX}/lib/cmake/${_realname}1"/*.cmake
}
